import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread("test.jpg")
assert isinstance(img, np.ndarray)

plt.imshow(img[:, :, ::-1])  # 进行色道的逆置，转换为bgr
b, g, r = cv2.split(img)  # 通道分离
plt.imshow(b, cmap=plt.cm.gray)
plt.show()

img2 = cv2.merge((b, g, r))  # 通道合并，返回rgb图像
plt.imshow(img2[:, :, ::-1])
plt.show()
